﻿Imports Microsoft.Win32
Public Class NetHlp
    Public Shared Function GetAdapterDisplayNameByInterfaceID(InterfaceID As Guid) As String
        Dim InterfaceKeyName As String = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{" & InterfaceID.ToString & "}\Connection"
        Dim IFName As String = ""
        Dim LocalMachine As RegistryKey
        Dim IFKey As RegistryKey
        Try
            ' obtain HKEY_LOCAL_MACHINE on both 32 and 64 bit systems
            If Environment.Is64BitOperatingSystem Then
                ' 64bit OS
                LocalMachine = Registry.LocalMachine.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
            Else
                ' 32bit OS
                LocalMachine = Registry.LocalMachine.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
            End If
            IFKey = LocalMachine.OpenSubKey(InterfaceKeyName)
            LocalMachine.Close()
            If IsNothing(IFKey) Then
                IFName = InterfaceID.ToString
            Else
                IFName = IFKey.GetValue("Name", "").ToString
            End If
            IFKey.Close()
            Return IFName
        Catch ex As Exception
            Return InterfaceID.ToString
        End Try
    End Function
End Class
